#pragma once
#include"BaseInc.h"

template<typename Sender, typename Args>
class EventHandler
{
	using eventFunc = function<void(Sender*, Args)>;
public:
	EventHandler() {}

	void operator += (function<void(Sender*, Args)> f)
	{
		//if (it == funcs.end())
		{
			funcs.push_back(f);
		}
	}
	void Invoke(Sender* s, Args arg)
	{
		for (int i = 0; i < funcs.size(); i++)
		{
			funcs[i](s, arg);
		}
	}
	void operator -= (function<void(Sender*, Args)> f)
	{
		//auto it = find(funcs.begin(), funcs.end(), f);
		//if (it == funcs.end())
		{
			//funcs.erase(it);
		}
	}
protected:
	std::vector<eventFunc> funcs;
};

